<html>
<head><meta charset="utf-8"><title>Hir: Traversing &quot;scope&quot; items up to the crate root. · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Hir.3A.20Traversing.20.22scope.22.20items.20up.20to.20the.20crate.20root.2E.html">Hir: Traversing &quot;scope&quot; items up to the crate root.</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="215205568"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Hir%3A%20Traversing%20%22scope%22%20items%20up%20to%20the%20crate%20root./near/215205568" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> popzxc <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Hir.3A.20Traversing.20.22scope.22.20items.20up.20to.20the.20crate.20root.2E.html#215205568">(Oct 31 2020 at 18:40)</a>:</h4>
<p>I'm currently working on a way to look up item attributes applied to the code item, including ones derived from the parent items.<br>
Short-term goal is to check for <code>allow(..)</code> attributes in items case diagnostic, but the long-term goal is to provide an interface to make this kind of information to any <code>hir</code> item that needs it.</p>
<p>So far I'm struggling with finding a way to find a next parent item which has attributes, e.g. `function -&gt; function -&gt; impl block -&gt; mod -&gt; mod -&gt; crate root".</p>
<p>Code example: <a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=259aadbe3bd5af7344c3c37302ae2d27">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=259aadbe3bd5af7344c3c37302ae2d27</a></p>
<p>In this example, given the <code>InnerData</code> structure ID, I would want to sequentially get the IDs of the following items: <code>inner_foo</code> -&gt; <code>foo</code> -&gt; <code>impl Data</code> -&gt; <code>b</code> -&gt; <code>a</code> -&gt; <code>crate root</code>.<br>
And of course, this structure can be split over multiple files, if that's important.</p>
<p>Ideally, I would want to be able to do the least possible amount of work getting the parent, so that traversal could be efficiently finished once required item is found.</p>
<p>Do you have any hints how to achieve this (or at least direction to think in)?</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>